import java.io.*;
import java.sql.*;
import java.util.StringTokenizer;
import oracle.jdbc.driver.OracleDriver;

public class ActBit {
  public static void main(String[] args)
    throws SQLException {
    if (args.length != 6) {
      System.err.println("Uso: java ActDB servidor puerto sid usuario pass tipo_archivo");
      System.exit(-1);
    }

    File archivo = null;
    FileReader fr = null;
    BufferedReader br = null;
    String ip = args[0];
    String puerto = args[1];
    String sid = args[2];
    String user = args[3];
    String pass = args[4];
    String arch_in = args[5];
    
    try  {
      archivo = new File(arch_in);
      fr = new FileReader(archivo);
      br = new BufferedReader(fr);

      DriverManager.registerDriver(new OracleDriver());

      Connection conn = DriverManager.getConnection(
        "jdbc:oracle:thin:@" + ip + ":" + puerto + ":" + sid, user, pass);

      PreparedStatement bitacora = null;
      
      String linea;
      bitacora = conn.prepareStatement("INSERT INTO XML_BIT_TEST" + 
        " VALUES (?,?,?,?,?,TO_DATE(?,'YYYYMMDDHH24MISS'))");

      while ((linea = br.readLine()) != null) {
        StringTokenizer datos = new StringTokenizer(linea, "|");
        int items = datos.countTokens();
        if (datos.hasMoreTokens()) {
          for (int i = 1; i <= items; i++) {
        	//System.out.println(i + " " + datos.nextToken().toString());
            bitacora.setString(i, datos.nextToken());
          }
          bitacora.executeUpdate();
        }
      }
      bitacora.close();
      conn.close();
    }
    catch (Exception e) {
      e.printStackTrace();
      try {
        if (fr != null) {
          fr.close();
        }
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
    finally {
      try {
        if (fr != null) {
          fr.close();
        }
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
  }
}